﻿<%@ Control Language="C#" AutoEventWireup="true" Codebehind="ucPostQuestion.ascx.cs"
    Inherits="ExpertMIS.Forums.UserControl.ucPostQuestion" %>
<%@ Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" TagPrefix="FCKeditorV2" %>

<script type="text/javascript">
    var expertList = null;
    var txTitleID = '#<% Response.Write(txTitle.ClientID); %>';

    function getExpertListCB(v) {
        expertList = $('#tdExpertList').append(v).children();
    }

    function getExpertList() {
        if (expertList == null) {
            var domains = '';
            $("span[domain] input").each(function() {
                if (this.checked) {
                    if (domains != '') domains += ',';
                    domains += $(this.parentNode).attr('domain');
                }
            });

            $.get('<% Response.Write(ExpertMIS.Codes.Utility.GetWebRoot(this,"~/Service/ExpertListService.aspx")); %>',
            { returntype: 'html', chooseddomain: domains }, getExpertListCB, 'html');
        }
        else {
            $(expertList).show();
        }
    }

    function validate(jqobj) {
        if (jqobj.val() === '') {
            jqobj.focus();
            return false;
        }
        if (jqobj.attr('minlength')) {
            if (jqobj.val().length < jqobj.attr('minlength')) {
                jqobj.focus();
                return false;
            }
        }
        return true;
    }

    function validateDomain() {
        var count = 0;
        var sDomain = '';
        $("span[domain] input").each(function() {
            if (this.checked) {
                count++;
                if (sDomain != '') sDomain += ',';
                sDomain += $(this.parentNode).attr('domain');
            }
        });

        $('#txDomains').val(sDomain);
        return count > 0;
    }

    function validateExpert() {
        var experts = '';
        $("input[expert]").each(function() {
            if (this.checked) {
                if (experts != '') experts += ',';
                experts += $(this).attr('expert');
            }
        });

        $('#txExperts').val(experts);
        //alert($('#txExperts').val());
    }

    function toExpert(flag) {
        var count = 0;
        $("span[domain] input").each(function() {
            if (this.checked) {
                count++;
            }
        });

        if (flag && count > 0) {
            $('#trExpertList').show();
            getExpertList($('#tdExpertList'));
        }
        else {
            $('#trExpertList').hide();
        }
    }

    function doPost() {
        if (!validate($(txTitleID))) {
            alert("请填写[问题标题]，至少" + $(txTitleID).attr('minlength') + "个字。");
            return false;
        }

        if (!validateDomain()) {
            alert('请选择该问题所属行业以便相关行业专家回应您的提问，至少一个行业。');
            return false;
        }

        validateExpert();

        return true;
    }

    function chooseDomain(el, chooseChilds) {
        if (chooseChilds) {
            var domain = $(el.parentNode).attr('domain');
            $("span[parentdomain='" + domain + "'] input[type='checkbox']").attr('checked', el.checked);
        }
        if (expertList != null) {
            $(expertList).remove();
            expertList = null;
            getExpertList();
        }
    }
</script>

<div class="questpost">
    <form id="frmQuestion" runat="server" onsubmit="return doPost();">
        <input type="hidden" id="txDomains" name="txDomains" />
        <input type="hidden" id="txExperts" name="txExperts" />
        <br />
        <table>
            <tr>
                <td style="width: 90px">
                    提问标题</td>
                <td style="width: 600px">
                    <asp:TextBox runat="server" ID="txTitle" Style="border: black 1px solid; width: 98%;"
                        MaxLength="100" /></td>
            </tr>
            <tr>
                <td style="width: 90px">
                    提问内容</td>
                <td style="width: 600px">
                    <asp:TextBox ID="txContent" runat="server" TextMode="MultiLine" Style="border: black 1px solid;
                        width: 98%; height: 200px;">
                    </asp:TextBox></td>
            </tr>
            <tr>
                <td style="width: 90px; height: 30px;">
                    设置分类</td>
                <td style="width: 600px; height: 30px; padding-top: 10px;">
                    <asp:DataList ID="dlDomains" runat="server" RepeatColumns="5" RepeatDirection="Horizontal"
                        Width="98%" OnItemDataBound="dlDomains_ItemDataBound" BorderColor="#595959" BorderStyle="Solid"
                        BorderWidth="0px">
                        <ItemStyle Width="120px" Font-Size="10pt" VerticalAlign="Middle" />
                        <ItemTemplate>
                            <asp:Panel ID="pnDomain" runat="server" Width="120px" Style="height: auto;" BorderStyle="None">
                                <asp:CheckBox ID="chkDomainRoot" runat="server" Text='<%# Eval("DomainName") %>'
                                    domain='<%# Eval("OID") %>' Font-Size="9pt" onclick="chooseDomain(this,true);" />
                                <asp:DataList ID="dlChilds" runat="server" RepeatDirection="Vertical" RepeatLayout="Flow">
                                    <ItemTemplate>
                                        <div style="padding-left: 8px; font-size: 7pt">
                                            <asp:CheckBox ID="chkDomain" runat="server" Text='<%# Eval("DomainName") %>' domain='<%# Eval("OID") %>'
                                                onclick="chooseDomain(this,false);" />
                                        </div>
                                    </ItemTemplate>
                                </asp:DataList>
                            </asp:Panel>
                        </ItemTemplate>
                    </asp:DataList>
                </td>
            </tr>
            <tr runat="server" visible="true" id="trAskForExpert">
                <td style="width: 90px; height: 20px;">
                    我问专家</td>
                <td style="width: 600px; height: 20px;">
                    <input type="checkbox" name="chkToExpert" onclick="toExpert(this.checked);" />
                    行业专家提问(请勾选您要咨询的专家)
                </td>
            </tr>
            <%--            <tr id="tr4" style="display: none;">
                <td>
                </td>
                <td id="td1" class="service-expert-list" colspan="2" style="height: 21px">
                </td>
            </tr>--%>
            <tr id="trExpertList" style="display: none;">
                <td class="service-expert-list" colspan="1" style="width: 90px; height: 21px">
                </td>
                <td id="tdExpertList" class="service-expert-list" style="height: 21px;
                    width: 600px;">
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <asp:ImageButton ID="btnPost" runat="server" ImageAlign="AbsMiddle" ImageUrl="~/imgs/forums/questionpost.gif"
                        OnClick="btnPost_Click" /></td>
            </tr>
        </table>
        <%--<br />
        <br />
        <br />
        <table>
            <tr>
                <td style="height: 16px;" colspan="2" class="qcolmerge">
                </td>
            </tr>
            <tr>
                <td class="qcol1">
                    提问标题
                </td>
                <td class="qcol2" style="width: 630px">
                    &nbsp;</td>
            </tr>
            <tr>
                <td style="vertical-align: top;" class="qcol1">
                    提问内容
                </td>
                <td class="qcol2" runat="server" id="tdQuestionContent" style="width: 630px">
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="qcol1" style="vertical-align: top; padding-top: 5px; height: 75px;">
                    设置分类
                </td>
                <td class="qcol2" style="overflow: scroll; width: 630px; height: 75px;">
                    &nbsp;</td>
            </tr>
            <tr runat="server" visible="true" id="trAskForExpert1">
                <td class="qcol1">
                    我问专家
                </td>
                <td class="qcol2" style="width: 630px">
                </td>
            </tr>
            <tr id="trExpertList1" style="display: none;">
                <td id="tdExpertList1" class="service-expert-list" colspan="2" style="height: 21px">
                </td>
            </tr>
            <tr id="Tr2" runat="server" visible="false">
                <td class="qcol1">
                    手机号码
                </td>
                <td class="qcol2" style="width: 630px">
                    <input type="text" id="txPhone" name="txPhone" style="border: black 1px solid; width: 260px;"
                        value='<% Response.Write(GetCurrentUserInfo("CellPhone"));%>' />
                </td>
            </tr>
            <tr id="Tr1" runat="server" visible="false">
                <td class="qcol1">
                    您的姓名
                </td>
                <td class="qcol2" style="width: 630px">
                    <input type="text" id="txName" name="txName" style="border: black 1px solid; width: 260px;"
                        value='<% Response.Write(GetCurrentUserInfo("Name")); %>' />
                </td>
            </tr>
            <tr runat="server" visible="false" id="Tr3">
                <td class="qcol1">
                    电子邮箱
                </td>
                <td class="qcol2" style="width: 630px">
                    <input type="text" id="txEMail" name="txEMail" style="border: black 1px solid; width: 260px;"
                        value='<% Response.Write(GetCurrentUserInfo("EMail"));%>' />
                </td>
            </tr>
            <tr>
                <td colspan="2" style="height: 30px;">
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td colspan="2" style="text-align: center">
                    &nbsp;</td>
            </tr>
        </table>--%>
    &nbsp; &nbsp;
    &nbsp; &nbsp;
    </form>
</div>
